<template>
	<div id="app">
		<!--应用程序栏-->
		<v-app-bar app color="#FF5252">
			<v-list-item-title style="text-align: center;font-size:18px;color:white">我的收藏</v-list-item-title>
			<v-btn elevation="0" small color="#FF5252" router-link :to="{ path: '/main/mine' }" class="go_back">
				<icon name="back" scale="2" color="white"></icon>
			</v-btn>
		</v-app-bar>

		<div class="no_content" v-if="is_null">
			<icon name="no_content" scale="15"></icon>
		</div>

		<div v-if="is_content">
			<div v-for="(house,i) in house_list" :key="i">
				<v-list-item three-line >
					<v-list-item-avatar tile size="100" width="130" class="image_border_list"><img :src="house.index_image_url" alt="未加载" />
					</v-list-item-avatar>
					<v-list-item-content>
						<v-list-item-title class="headline mb-1" style="font-size: 17px !important;">
							{{house.title}}
						</v-list-item-title>		
						<v-list-item-subtitle><span>{{house.area_name}}</span>&nbsp;|&nbsp;<span>{{house.lease_type}}</span>&nbsp;|&nbsp;<span>{{house.acreage}}m²</span>&nbsp;|&nbsp;<span>{{house.renovation}}</span></v-list-item-subtitle>
						<div class="overline" style="color:#FF5252">{{house.month_price}}元/月
							<div style="float: right;margin-right:1% ;" @click="delCollected(house.house_id)">
									<icon name="delete" scale="2"></icon>
							</div>
						</div>					
					</v-list-item-content>
				</v-list-item>
			</div>
		</div>
		<v-snackbar v-model="snackbar" bottom :timeout="timeout">
			{{ message }}
		</v-snackbar>
	</div>
</template>

<script>
	import axios from "axios";
	export default {
		name: "Collection",
		data() {
			return {
				absolute: true,
				overlay: false,
				house_list: [],
				is_content:false,
				is_null:false,
				snackbar:false,
				message:'',
				timeout:1000
			}
		},
		methods:{
			delCollected(house_id) {
				let _this = this;
				axios
					.delete("/api/v1.0/users/del_user_collected",{
						params: {
							house_id:house_id
						}
					})
					.then(function(response) {
						if (response.data.errno == '0') {
							_this.snackbar = true;
							_this.message = response.data.errmsg
							setTimeout(function() {
								_this.$router.go(0)
							}, 1000);
						} else if (response.data.errno == '4101') {
							// 未登跳转到登录页面
							setTimeout(function() {
								_this.$router.replace({
									path: "/login"
								});
							}, 1000);
						}
					})
					.catch(function() {
						_this.message = "连接服务器失败！";
					});
			},
		},
		mounted() {
			let _this = this;
			axios
				.get("/api/v1.0/users/get_user_collected")
				.then(function(response) {
					if (response.data.errno === '0') {
						_this.house_list = response.data.data;
						console.log(response.data.data);
						if (_this.house_list.length == 0) {
							_this.is_null = true;
						} else {
							_this.is_content = true;
						}
					} else if (response.data.errno === '4101') {
						// 未登跳转到登录页面
						setTimeout(function() {
							_this.$router.replace({
								path: "/login"
							});
						}, 1000);
					}
				})
				.catch(function() {
					_this.message = "连接服务器失败！";
				});
		}
	}
</script>

<style scoped>

</style>
